

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.TimerTask;

public class MapConnector extends TimerTask {

	private int prev_x = -9999;
	private int prev_y = -9999;
	private int prev_area = -9999;
	
	private int x_length = 0;
	private int y_length = 0;
	
	MapController parent = null;
	
	public MapConnector (MapController __parent) {
		this.parent = __parent;
	}
	
	public void set_length (int x_length, int y_length) {
		this.x_length = x_length;
		this.y_length = y_length;
	}
	
	// GET CURRENT POSITION FROM SERVER
	//
	public int[] getMyPostion () {
		
		// INPUT YOUR GPS CODE FOR CURRENT MY POSTION
		//
		int x = Main.Navi.getLoc()[0];//(int) (Math.random() * this.x_length);
		int y = Main.Navi.getLoc()[1];//(int) (Math.random() * this.y_length);
		int area = Main.Navi.getMyChildId();
		
		int[] position = new int[6];
		
		position[0] = x;
		position[1] = y;
		position[2] = area;
		position[3] = this.prev_x;
		position[4] = this.prev_y;
		position[5] = this.prev_area;
		
		this.prev_x = x;
		this.prev_y = y;
		this.prev_area = area;
		
		return position;
	}
	
	// REPAINT
	//
	@Override
	public void run() {
		// TODO Auto-generated method stub
		
		int[] position = this.getMyPostion();

		this.parent.map.load(position[0], position[1], position[2]);
		this.parent.map.draw();		
	}
}
